<%@ Page Language="c#" Inherits="PHSRAG.Insight.Agreements.ArraPIQuestionnairePage" CodeFile="ArraPIQuestionnaire.aspx.cs"%>
<%@ Import Namespace="PHSRAG.Insight.Agreements.Arra"%>
<%@ Import Namespace="PHSRAG.Utility"%>
<%@ Import Namespace="System.Collections.Generic"%>

<%@ Register TagPrefix="cc2" Namespace="PHSRAG.WebControls" Assembly="PHSRAG.WebControls" %>
<%@ Register TagPrefix="cc1" Namespace="PHSRAG.Insight21.InsightWebControls" Assembly="PHSRAG.Insight21.InsightWebControls" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>ARRA Quarterly Reporting</title>
    <link href="../Insight21.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript">
    
    function OnImgBtnDeleteJobClick()
    {
        if ($('#hdnJobRowCount').val() != 0)
        {
            if (confirm('Are you sure you want to delete last job entered?'))
            {
                $('#<%=ControlNameBaseTrJob%>' + $('#hdnJobRowCount').val()).remove();
                $('#hdnJobRowCount').val(parseInt($('#hdnJobRowCount').val()) - 1);
            }
            
            CalculateNumberOfJobs();
        }

        return false;
    }
    
    function OnImgBtnAddNewJobClick()
    {
        AddNewJobTableRow();
        $('#hdnJobRowCount').val(parseInt($('#hdnJobRowCount').val()) + 1);
        
        CalculateNumberOfJobs();
        
        return false;
    }
    
    function AddNewJobTableRow()
    {
        var newJobRowNumber = parseInt($('#hdnJobRowCount').val()) + 1;
        var cssClassName;
        
        if ((newJobRowNumber % 2) == 0)
        {
            cssClassName = '<%=CssClassNameDataGridItem%>';
        }
        else
        {
            cssClassName = '<%=CssClassNameDataGridAlternatingItem%>';
        }
        
        var newRowHtml =    '<tr id="trJob' + newJobRowNumber + '" class="' + cssClassName + '">';
        newRowHtml +=       '<td><select name="<%=ControlNameBaseDdlJobType%>' + newJobRowNumber + '" id="<%=ControlNameBaseDdlJobType%>' + newJobRowNumber + '" onchange="CalculateNumberOfJobs();">';
        newRowHtml +=       '<option value="0" selected="1">Select</option>';
        <% 
            foreach (KeyValuePair<int, string> jobType in PIQuestionnaire.JobTypes)
            {
                %>
                newRowHtml += '<option value="<%=jobType.Key%>"><%=jobType.Value%></option>';
                <%
            }
        %>
        newRowHtml +=       '</select></td>';
        newRowHtml +=       '<td><input name="<%=ControlNameBaseTxtJobTitle%>' + newJobRowNumber + '" type="text" maxlength="40" id="<%=ControlNameBaseTxtJobTitle%>' + newJobRowNumber + '" style="width:300px;" /></td>';
        newRowHtml +=       '<td><input name="<%=ControlNameBaseTxtPercentEffort%>' + newJobRowNumber + '" type="text" maxlength="3" id="<%=ControlNameBaseTxtPercentEffort%>' + newJobRowNumber + '" style="width:50px;" onkeyup="CalculateNumberOfJobs();" />%</td>';
        newRowHtml +=       '</tr>';
		
        $('#tfJobsCreated').before(newRowHtml);
    }
    
    function GetNumberOfJobs(jobTypeID)
    {
        var rowCount = parseInt($('#hdnJobRowCount').val());
        var sum = 0;
        
        for (var i = 1; i <= rowCount; i++)
        {
            if ($('#<%=ControlNameBaseDdlJobType%>' + i).val() == jobTypeID)
            {
                if (IsUnsignedInteger($('#<%=ControlNameBaseTxtPercentEffort%>' + i).val()))
                {
                    sum += parseInt($('#<%=ControlNameBaseTxtPercentEffort%>' + i).val())/100;
                }
            }
        }
        
        return sum;
    }
    
    function CalculateNumberOfJobs()
    {
        $('#lblJobsCreated').text(GetNumberOfJobs(1));
        $('#lblJobsRetained').text(GetNumberOfJobs(2));
    }
    
    function IsUnsignedInteger(s) 
    {
        return (s.toString().search(/^[0-9]+$/) == 0);
    }
    
    function OnCancelClick()
    {
        window.location.href = '<%=ResolveUrl(Settings.GetKeyValue(ConfigKeyArraPIQuestionnaireListUrl, string.Empty))%>';
        return false;
    }

    </script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function(){
            CalculateNumberOfJobs();
            
            if ($('#validationSummary1').length > 0)
            {
                alert('There was an error saving the questionnaire. Please fix the errors and try again.');
            }
        });
    </script>
    <form id="arraPIQuestionnaireForm" method="post" runat="server">
        <asp:HiddenField ID="hdnJobRowCount" runat="server" />
        <table class="Container">
            <tr>
                <td>
                    <table class="Header">
                        <tr>
                            <td>
                                <cc1:Header ID="header" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc1:AgreementsSubNavigation ID="agreementsSubNavigation" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc2:BreadCrumb ID="breadCrumb" runat="server" />
                            </td>
                        </tr>
                    </table>
                    <table id="dynamicTable" class="Invisible" cellspacing="10">
                        <tr>
                            <td>
                                <cc2:ActivityIndicator ID="activityIndicator" runat="server" ContainerID="dynamicTable" />
                            </td>
                        </tr>
						<tr>
							<td>
								<cc2:Annunciator ID="annunciator" runat="server" ContainerID="dynamicTable" />
							</td>
						</tr>
                    </table>
                    <div>
                        <asp:ValidationSummary ID="validationSummary1" runat="server" CssClass="ValidationSummary" DisplayMode="List"
                            EnableClientScript="False" />
                    </div>
                    <div id="divContent" runat="server">
                        <div class="Center MarginedLeft MarginedRight">
                            <h1>
                                Partners Research Management<br />
                                ARRA Quarterly Reporting</h1>
                        </div>
                        <div class="MarginedLeft MarginedRight">
                            <h2>
                                Project Summary</h2>
                        </div>
                        <div class="FramedContainer Padded Margined">
                            <table cellspacing="5px">
                                <tr>
                                    <td>
                                        Principal Investigator:</td>
                                    <td colspan="4">
                                        <asp:Label ID="lblPI" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        Project Title:</td>
                                    <td colspan="4">
                                        <asp:Label ID="lblProjectTitle" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                    <td style="width: 50px;">
                                    </td>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        PeopleSoft Number:</td>
                                    <td>
                                        <asp:Label ID="lblPeopleSoftNumber" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                    <td style="width: 50px;">
                                    </td>
                                    <td>
                                        Chief of Service Code:</td>
                                    <td>
                                        <asp:Label ID="lblChiefOfServiceCode" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td style="height: 14px">
                                        Organization:</td>
                                    <td style="height: 14px">
                                        <asp:Label ID="lblOrganization" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                    <td style="width: 50px; height: 14px;">
                                    </td>
                                    <td style="height: 14px">
                                        Department:</td>
                                    <td style="height: 14px">
                                        <asp:Label ID="lblDept" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        Sponsor:</td>
                                    <td>
                                        <asp:Label ID="lblSponsor" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                    <td style="width: 50px">
                                    </td>
                                    <td>
                                        Sponsor Award Number:</td>
                                    <td>
                                        <asp:Label ID="lblSponsorAwardNumber" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        Quarter Ending On:</td>
                                    <td>
                                        <asp:Label ID="lblQuarterEndingOn" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                    <td style="width: 50px;">
                                    </td>
                                    <td>
                                        Dept. Admin:</td>
                                    <td>
                                        <asp:Label ID="lblDeptAdmin" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                </tr>
                                <tr>
                                    <td>
                                        Research Mgmt Admin:</td>
                                    <td>
                                        <asp:Label ID="lblResearchMgmtAdmin" runat="server" Font-Bold="True" Text="Label"></asp:Label></td>
                                    <td style="width: 50px">
                                    </td>
                                    <td>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="Margined">
                            <h2>
                                Award Description</h2>
                            <div class="MarginedTop">
                                A narrative description of the employment impact of the Recovery Act funded work. 
                                This narrative is cumulative for each calendar quarter and at a minimum, will 
                                address the impact on the recipient's or federal contractor's workforce (for 
                                grants and loans, recipients shall also include the impact on the workforces 
                                of sub recipients and vendors).  The description should capture the overall 
                                purpose of the award.  For example, "community development", "comprehensive 
                                community mental health services to adults with a serious mental illness", etc.  
                                This narrative field has a 4000 character limit and is a required field.  
                            </div>
                        </div>
                        <div class="FramedContainer Padded Margined" runat="server" visible="false" id="divAwardDescriptionReadOnly">
                            <asp:Label ID="lblAwardDescription" runat="server"></asp:Label>
                        </div>
                        <div class="Margined" id="divAwardDescription" runat="server">
                            <asp:TextBox ID="txtAwardDescription" runat="server" MaxLength="4000" Width="98%"
                                Height="150px" CausesValidation="True" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="cvAwardDescription" runat="server" ControlToValidate="txtAwardDescription"
                                EnableClientScript="False" ErrorMessage="Please enter award description." Font-Size="Large">*</asp:RequiredFieldValidator></div>
                        <div class="Margined">
                            <h2>
                                Quarterly Activities/Project Description</h2>
                            <div class="MarginedTop">
                                A description of the overall purpose and expected outputs and outcomes or results 
                                of the award and first-tier Subaward(s), including significant deliverables and, 
                                if appropriate, units of measure.  This narrative field has a 2000 character limit 
                                and is a required field.  </div>
                        </div>
                        <div class="FramedContainer Padded Margined" runat="server" visible="false" id="divProjectDescriptionReadOnly">
                            <asp:Label ID="lblProjectDescription" runat="server"></asp:Label>
                        </div>
                        <div class="Margined" id="divProjectDescription" runat="server">
                            <asp:TextBox ID="txtProjectDescription" runat="server" MaxLength="2000" Width="98%"
                                Height="100px" CausesValidation="True" TextMode="MultiLine"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="cvProjectDescription" runat="server" ControlToValidate="txtProjectDescription"
                                EnableClientScript="False" ErrorMessage="Please enter quarterly activities / project description."
                                Font-Size="Large">*</asp:RequiredFieldValidator></div>
                        <div class="Margined">
                            <h2>
                                Jobs Created and Retained</h2>
                            <div class="MarginedTop">
                                The Jobs Created and Retained Section is used to populate the "Number of Jobs" and percent effort fields of the reporting requirement.</div>
                        </div>
                        <table class="DataGrid MarginedBottom" runat="server" id="tblJobs" width="100%">
                            <tr class="DataGridHeader">
                                <td>
                                    Job Type
                                </td>
                                <td>
                                    Job Title
                                </td>
                                <td>
                                    % Effort
                                </td>
                            </tr>
                            <tr class="DataGridFooter" id="tfJobsCreated">
                                <td width="80%" colspan="2" class="Right">
                                    Total Number of Jobs Created:
                                </td>
                                <td width="20%">
                                    <asp:Label ID="lblJobsCreated" runat="server"></asp:Label>
                                </td>
                            </tr>
                            <tr class="DataGridFooter" id="tfJobsRetained">
                                <td width="80%" colspan="2" class="Right">
                                    Total Number of Jobs Retained:
                                </td>
                                <td width="20%">
                                    <asp:Label ID="lblJobsRetained" runat="server"></asp:Label>
                                </td>
                            </tr>
                        </table>
                        <div class="Margined Right" runat="server" id="divJobButtons">
                            <asp:ImageButton ID="imgBtnAddNewJob" runat="server" AlternateText="Add New Job"
                                OnClientClick="return OnImgBtnAddNewJobClick()" ImageUrl="~/Images/b_add_new_job.gif" />
                            <asp:ImageButton ID="imgBtnDeleteJob" runat="server" AlternateText="Delete Job" OnClientClick="return OnImgBtnDeleteJobClick()" ImageUrl="~/Images/b_delete_job.gif" />
                        </div>
                        <div class="Margined Right" runat="server" id="divSaveButtons">
                            <asp:ImageButton ID="imgBtnSaveDraft" runat="server" AlternateText="Save Draft" OnClick="OnImgBtnSaveDraftClick" ImageUrl="~/Images/b_save_draft.gif" />
                            <asp:ImageButton ID="imgBtnComplete" runat="server" AlternateText="Complete and Finalize " ImageUrl="~/Images/b_complete_finalize.gif" OnClick="OnImgBtnCompleteClick" />
                            <asp:ImageButton ID="imgBtnCancel" runat="server" AlternateText="Cancel" CausesValidation="False" ImageUrl="~/Images/b_cancel.gif" OnClientClick="return OnCancelClick();" />
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
